package com.yanqu.road.server.cmd.activity.yqhotel;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.YqHotelProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;

import com.yanqu.road.server.gameplayer.module.activity.yqhotel.YqHotelModule;
import com.yanqu.road.server.manger.activity.yqhotel.YqHotelMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_YQ_HOTEL_ENTER_SCENE, desc = "阳泉酒家进入游戏界面大场景要开始同步")
public class YqHotelEnterSceneCmd extends AbstractCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        YqHotelProto.YqHotelEnterReqMsg reqMsg = YqHotelProto.YqHotelEnterReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!YqHotelMgr.activityInTime()){
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        //如果没解锁
        if (!SystemOpenMgr.systemOpen(player, eSystemId.YQHotel.getValue())){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }

        Object locker = player.getModule(YqHotelModule.class).getLocker();
        synchronized (locker){
            YqHotelProto.YqHotelEnterRespMsg.Builder respMsg = player.getModule(YqHotelModule.class).enterScene(player.getUserId());
            player.sendPacket(ClientProtocol.U_YQ_HOTEL_ENTER_SCENE, respMsg);
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            YqHotelProto.YqHotelEnterRespMsg.Builder respMsg = YqHotelProto.YqHotelEnterRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_YQ_HOTEL_ENTER_SCENE, respMsg);
        }
    }
}
